package com.example.hyw.szysteam.presenter;

import com.example.hyw.szysteam.POJO.HttpResult;
import com.example.hyw.szysteam.POJO.User;
import com.example.hyw.szysteam.POJO.UserInfo;
import com.example.hyw.szysteam.model.UserModel;
import com.example.hyw.szysteam.view.EditInfoActivity;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by HYW on 2018/6/6.
 */

public class UserInfoPresenter {
    private UserModel userModel=new UserModel();
    private EditInfoActivity editInfoActivity;

    public UserInfoPresenter(EditInfoActivity editInfoActivity) {
        this.editInfoActivity = editInfoActivity;
    }

    public void editInfo(final String email,final String name,final String school,final boolean sex,final int age){
        userModel.editInfo(email,name,school,sex,age)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<HttpResult<User>>() {
                    @Override
                    public void accept(HttpResult<User> userHttpResult) throws Exception {
                        User user=userHttpResult.getContent();
                        UserInfo.setName(user.getName());
                        UserInfo.setSchool(user.getSchool());
                        UserInfo.setSex(user.isSex());
                        UserInfo.setAge(user.getAge());
                        editInfoActivity.editSuccess();
                    }
                });
    }
}
